package com.iflytek.yly.jetpackdemo.databinding;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.iflytek.yly.jetpackdemo.R;

import java.util.List;

public class RecyclerViewAdapter extends RecyclerView.Adapter<MyViewHolder> {

    private List<Book2> books;

    public RecyclerViewAdapter(List<Book2> books) {
        this.books = books;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        RvItemBookBinding rvItemBookBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),
                R.layout.rv_item_book,
                parent,
                false);
        return new MyViewHolder(rvItemBookBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        Book2 book = books.get(position);
        holder.rvItemBookBinding.setBook(book);
    }

    @Override
    public int getItemCount() {
        return books.size();
    }
}

